﻿/*
 *  Program.cs
 *
 *  Copyright (C) 2008 Dreamlusion <dreamlusion@gmail.com>
 *
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License version
 *      2 as published by the Free Software Foundation.
 *
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Web;
using System.Text.RegularExpressions;
using phpMyAdminToolkit.Common;

namespace phpMyAdminToolkit.Dump
{
	class Program
	{
		const string Usage = "Usage: phpMyAdminExport --user=exampleUser --password=examplePass --databaseName=exampleDB --backupDirectory=\"C:\\example with quotes\\backups\" --pmaBase=\"http://www.url-escaped-example.com/phpMyAdmin\" [--includeTables=^(table1|table2)$] [--excludeTables=^(table3|table4)$] [--sqlCommand=\"delete from cache;\"]";

		static void Main(string[] args)
		{
			Parameters parameters = new Parameters(args);

			if (parameters.Usage)
			{
				Console.WriteLine(Usage);
				return;
			}

			phpMyAdminDumper dumper = new phpMyAdminDumper();

			dumper.Activity += delegate(object sender, phpMyAdminActivity e)
			{
				Console.WriteLine(e.Message);
			};

			bool success = false;
			try
			{
				dumper.Dump(parameters.PmaUri,
					parameters.User,
					parameters.Password,
					parameters.DatabaseName,
					parameters.BackupDirectory,
					parameters.SqlCommand,
					parameters.IncludedTables,
					parameters.ExcludedTables);

				success = true;
			}
			catch (ArgumentException ex)
			{
				Console.WriteLine();
				Console.WriteLine(Usage);
				Console.WriteLine();
				Console.WriteLine(ex.Message);
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex);
			}

			if (!success)
				Console.Write("Press any key to exit..."); Console.Read();
		}
	}
}
